package com.example.first;

import android.os.Bundle;
import android.renderscript.Sampler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG="AAA";
    TextView v;
    EditText et1,et2;
    String p1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);//`res的资源项
        v = (TextView) findViewById(R.id.t2);
        et1 = (EditText) findViewById(R.id.et1);
         et2 = (EditText) findViewById(R.id.et2);
        Button btn = (Button) findViewById(R.id.btp);
        btn.setOnClickListener(this);//增加监听
        //System.out.println("hello from onCreat()...");
        //Log.i("aa","msgg from logi");//日志处理
       // Log.i(TAG, "onCreate: ");
    }

    /*public void btn(View vs){
        Log.i(TAG, "btn: bcahk1");
        et=findViewById(R.id.et);
           v = findViewById(R.id.t2);
         String s1=et.getText().toString();
          double s2 =Double.parseDouble(s1);
         double s3=1.8*s2+32;

        Log.i(TAG, "onClick: s1="+s1);
           v.setText();
    }                    */
    @Override
    public void onClick(View view) {
        Log.i(TAG, "onClick: clc1111");
        et1=findViewById(R.id.et1);
        et2=findViewById(R.id.et2);
        v = findViewById(R.id.t2);
      String s1=et1.getText().toString();
       String s2=et2.getText().toString();
       double s3=Double.parseDouble(s1);
      double s4 =Double.parseDouble(s2);
      double s5= s4/(s3*s3);
       DecimalFormat df = new DecimalFormat("#.00");
      String s6 = String.valueOf(df.format(s5));
      if (s5<18.5){
            p1="低体重阶段，当前需补充营养，不宜减肥";
      } else if (s5>=18.5&s5<24.0){
            p1="正常体重阶段，可继续保持饮食。";
        } else if (s5>=24.0&s5<28.0){
           p1="肥胖前期阶段，应当克制当前饮食，少吃油腻的食物，降低糖的摄入。";
      }  else {
           p1="肥胖阶段，应采取适当的减肥方法，控制饮食。";
      }
        Log.i(TAG, "onClick: s1="+s1);

     v.setText("您的BMI指数为"+s6+","+"\n"+"当前处于"+p1);
    }





}